package top.malegod.consumer;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import top.malegod.mapper.OtherMapper;
import top.malegod.mapper.UserMapper;
import top.malegod.model.User;


/**
 * Create by IntelliJ IDEA
 *
 * @author: AbelEthan
 * @date-Time: 2018/5/16 16:35
 * @description:
 */
public class UserConsumer implements MessageListener {

  @Autowired
  private UserMapper userMapper;

  @Override
  public void onMessage(Message message) {
    try {
      String s = new String(message.getBody(),"UTF-8");
      User user = new ObjectMapper().readValue(s, User.class);
      userMapper.insertUser(user);
      userMapper.addUserIntegral(user.getId());
    } catch (IOException e) {
      System.out.println(message.getMessageProperties().getMessageId());
      e.printStackTrace();
    }
  }
}
